// pages/visitor/profile/profile.js
var api = require('../../../utils/httpUtil.js');
const app = getApp();
Component({
  options: {
    addGlobalClass: true,
  },
  data: {
    imgUrl: api.imgUrl,
    tabCur: 0,
    scrollLeft: 0,
    tabList: ['通过', '拒绝'],
    openId: null,
    visitorList: [],
    visitorListHis: [],
    queryData: {},
  },
  lifetimes: {
    // 组件生命周期函数，在组件布局完成后执行，此时可以获取节点信息   
    ready: function () {
      // 在组件布局完成后执行的操作
      this.setData({
        openId: app.globalData.openId
      })
      this.loadData(1);
      this.loadData(2);
    }
  },
  methods: {
    tabSelect(e) {
      this.setData({
        tabCur: e.currentTarget.dataset.id,
      })
    },
    loadData(appStatus) {
      api.httpRequest(api.visitorListAPI, {
          openId: this.data.openId,
          status: appStatus
        })
        .then(res => {
          if (res.code == 200) {
            if (appStatus === 1) {
              this.setData({
                visitorList: res.data
              })
            } else {
              this.setData({
                visitorListHis: res.data
              })
            }

          } else {
            wx.showToast({
              title: res.msg,
              duration: 2000,
              mask: true,
              icon: 'none'
            })
          }

        })
        .catch(error => {
          wx.showToast({
            title: error.message,
            duration: 1000,
            mask: true,
            icon: 'none'
          })
        });
    }
  }
})